package demo2;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ASUS
 * Date: 2023-09-18
 * Time: 21:10
 */
/*
   *判断方程是否有根并计算方程的解

 */
public class Homework2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你想需要判断的方程中实数a，b，c的值(回车结束）");
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        double x1 = 0;
        double x2 = 0;
        double m = Math.sqrt(b * b - 4 * a *c);
        if ((b * b - 4 * a * c) < 0) {
            System.out.println("该方程无实数解");
        }else{
            if ((b * b - 4 * a * c) == 0){
                System.out.println("该方程只有一个实数解");
                int x = (-b)/(2*a);
                System.out.println("x=" + x);
            }else {
                System.out.println("该方程有两个实数解");
                x1 = (-b + m) / (2 * a);
                x2 = (-b - m) / (2 * a);

                System.out.println("x1=" + x1);
                System.out.println("x2=" + x2);
            }
        }
    }
}
